package org.sirmupadbapi.persistencia;

import org.sirmupadbapi.beans.Vehiclestraspaso;
import java.sql.Date; 
import org.sirmupadbapi.beans.*;
import org.sirmupadbapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.sirmupadbapi.generales.Mensajeria;
import org.sirmupadbapi.generales.DataGManager;


/**
*
* @author
*/

public class VehiclestraspasoPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
static DataGManager dataGManager;
static List<Vehiclestraspaso> list;

public VehiclestraspasoPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Vehiclestraspaso vehiclestraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into vehiclestraspaso(IDNUMERACIONTRASPASO,IDVEHICULO,PLACA,IDRECIBO,IDOLD,TIPOIDOLD,ID,TIPOID,ACTIVO,IDMUNICIPIO,FECHATRASPASO,FECHA,USERNAME)  values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setInt(1,vehiclestraspaso.getIDNUMERACIONTRASPASO());
        pinsert.setLong(2,vehiclestraspaso.getIDVEHICULO());
        pinsert.setString(3,vehiclestraspaso.getPLACA());
        pinsert.setInt(4,vehiclestraspaso.getIDRECIBO());
        pinsert.setString(5,vehiclestraspaso.getIDOLD());
        pinsert.setString(6,vehiclestraspaso.getTIPOIDOLD());
        pinsert.setString(7,vehiclestraspaso.getID());
        pinsert.setString(8,vehiclestraspaso.getTIPOID());
        pinsert.setString(9,vehiclestraspaso.getACTIVO());
        pinsert.setString(10,vehiclestraspaso.getIDMUNICIPIO());
        pinsert.setDate(11,vehiclestraspaso.getFECHATRASPASO());
        pinsert.setDate(12,vehiclestraspaso.getFECHA());
        pinsert.setString(13,vehiclestraspaso.getUSERNAME());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Vehiclestraspaso vehiclestraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update vehiclestraspaso set  IDNUMERACIONTRASPASO=?, IDVEHICULO=?, PLACA=?, IDRECIBO=?, IDOLD=?, TIPOIDOLD=?, ID=?, TIPOID=?, ACTIVO=?, IDMUNICIPIO=?, FECHATRASPASO=?, FECHA=?, USERNAME=?  where  IDNUMERACIONTRASPASO ='"+vehiclestraspaso.getIDNUMERACIONTRASPASO()+"' and  IDMUNICIPIO ='"+vehiclestraspaso.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,vehiclestraspaso.getIDNUMERACIONTRASPASO());
pupdate.setLong(2,vehiclestraspaso.getIDVEHICULO());
pupdate.setString(3,vehiclestraspaso.getPLACA());
pupdate.setInt(4,vehiclestraspaso.getIDRECIBO());
pupdate.setString(5,vehiclestraspaso.getIDOLD());
pupdate.setString(6,vehiclestraspaso.getTIPOIDOLD());
pupdate.setString(7,vehiclestraspaso.getID());
pupdate.setString(8,vehiclestraspaso.getTIPOID());
pupdate.setString(9,vehiclestraspaso.getACTIVO());
pupdate.setString(10,vehiclestraspaso.getIDMUNICIPIO());
pupdate.setDate(11,vehiclestraspaso.getFECHATRASPASO());
pupdate.setDate(12,vehiclestraspaso.getFECHA());
pupdate.setString(13,vehiclestraspaso.getUSERNAME());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  vehiclestraspaso set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Vehiclestraspaso vehiclestraspaso_old , Vehiclestraspaso vehiclestraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update vehiclestraspaso set  IDNUMERACIONTRASPASO=? ,  IDMUNICIPIO=?  where  IDNUMERACIONTRASPASO ='"+vehiclestraspaso_old.getIDNUMERACIONTRASPASO()+"' and  IDMUNICIPIO ='"+vehiclestraspaso_old.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,vehiclestraspaso.getIDNUMERACIONTRASPASO());pupdate.setString(10,vehiclestraspaso.getIDMUNICIPIO());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Vehiclestraspaso vehiclestraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiclestraspaso  where  IDNUMERACIONTRASPASO = ? and  IDMUNICIPIO = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(1,vehiclestraspaso.getIDNUMERACIONTRASPASO());
pdelete.setString(10,vehiclestraspaso.getIDMUNICIPIO());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiclestraspaso where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiclestraspaso  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Vehiclestraspaso vehiclestraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from vehiclestraspaso where IDNUMERACIONTRASPASO='"+vehiclestraspaso.getIDNUMERACIONTRASPASO()+"' and IDMUNICIPIO='"+vehiclestraspaso.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Vehiclestraspaso findByPrimaryKey(Vehiclestraspaso vehiclestraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from vehiclestraspaso where IDNUMERACIONTRASPASO='"+vehiclestraspaso.getIDNUMERACIONTRASPASO()+"' and IDMUNICIPIO='"+vehiclestraspaso.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            vehiclestraspaso.setIDNUMERACIONTRASPASO(rs.getInt("IDNUMERACIONTRASPASO"));
vehiclestraspaso.setIDVEHICULO(rs.getLong("IDVEHICULO"));
vehiclestraspaso.setPLACA(rs.getString("PLACA"));
vehiclestraspaso.setIDRECIBO(rs.getInt("IDRECIBO"));
vehiclestraspaso.setIDOLD(rs.getString("IDOLD"));
vehiclestraspaso.setTIPOIDOLD(rs.getString("TIPOIDOLD"));
vehiclestraspaso.setID(rs.getString("ID"));
vehiclestraspaso.setTIPOID(rs.getString("TIPOID"));
vehiclestraspaso.setACTIVO(rs.getString("ACTIVO"));
vehiclestraspaso.setIDMUNICIPIO(rs.getString("IDMUNICIPIO"));
vehiclestraspaso.setFECHATRASPASO(rs.getDate("FECHATRASPASO"));
vehiclestraspaso.setFECHA(rs.getDate("FECHA"));
vehiclestraspaso.setUSERNAME(rs.getString("USERNAME"));
    }
    rs.close();
    psquery.close();
 return vehiclestraspaso;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDNUMERACIONTRASPASO()
*/

public static List<Vehiclestraspaso> findByIDNUMERACIONTRASPASO(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where IDNUMERACIONTRASPASO='"+vehiclestraspaso.getIDNUMERACIONTRASPASO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDVEHICULO()
*/

public static List<Vehiclestraspaso> findByIDVEHICULO(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where IDVEHICULO='"+vehiclestraspaso.getIDVEHICULO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPLACA()
*/

public static List<Vehiclestraspaso> findByPLACA(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where PLACA='"+vehiclestraspaso.getPLACA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDRECIBO()
*/

public static List<Vehiclestraspaso> findByIDRECIBO(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where IDRECIBO='"+vehiclestraspaso.getIDRECIBO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDOLD()
*/

public static List<Vehiclestraspaso> findByIDOLD(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where IDOLD='"+vehiclestraspaso.getIDOLD()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTIPOIDOLD()
*/

public static List<Vehiclestraspaso> findByTIPOIDOLD(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where TIPOIDOLD='"+vehiclestraspaso.getTIPOIDOLD()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByID()
*/

public static List<Vehiclestraspaso> findByID(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where ID='"+vehiclestraspaso.getID()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTIPOID()
*/

public static List<Vehiclestraspaso> findByTIPOID(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where TIPOID='"+vehiclestraspaso.getTIPOID()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByACTIVO()
*/

public static List<Vehiclestraspaso> findByACTIVO(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where ACTIVO='"+vehiclestraspaso.getACTIVO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDMUNICIPIO()
*/

public static List<Vehiclestraspaso> findByIDMUNICIPIO(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where IDMUNICIPIO='"+vehiclestraspaso.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHATRASPASO()
*/

public static List<Vehiclestraspaso> findByFECHATRASPASO(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where FECHATRASPASO='"+vehiclestraspaso.getFECHATRASPASO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHA()
*/

public static List<Vehiclestraspaso> findByFECHA(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where FECHA='"+vehiclestraspaso.getFECHA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByUSERNAME()
*/

public static List<Vehiclestraspaso> findByUSERNAME(Vehiclestraspaso vehiclestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
      String sql = "select * from vehiclestraspaso where USERNAME='"+vehiclestraspaso.getUSERNAME()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Vehiclestraspaso> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiclestraspaso>();
  String sql = "select * from vehiclestraspaso";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from vehiclestraspaso";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from vehiclestraspaso where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from vehiclestraspaso";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from vehiclestraspaso where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Vehiclestraspaso> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Vehiclestraspaso>();
  String sql = "select * from vehiclestraspaso where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Vehiclestraspaso> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Vehiclestraspaso>();
  String sql = "select * from vehiclestraspaso";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiclestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Vehiclestraspaso vehiclestraspaso2 = new Vehiclestraspaso(
         rs.getInt("IDNUMERACIONTRASPASO"),rs.getLong("IDVEHICULO"),rs.getString("PLACA"),rs.getInt("IDRECIBO"),rs.getString("IDOLD"),rs.getString("TIPOIDOLD"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHATRASPASO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(vehiclestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
